<template>
    <div class="loading-main">
        <!-- <remote-script
      src="http://192.168.200.216:8701/web-apps/apps/api/documents/api.js"
      @load="createEditor"
    ></remote-script> -->
        <van-loading size="24px" vertical>加载中...</van-loading>
        <!-- <div id="onlyoffice"></div> -->
    </div>
</template>

<script>
import { Notify } from "vant";
import "@/utils/importJS.js";
import { postAction, getAction } from "@/api/manage";
import { queryUserRoleInfo } from "@/api/api";
import { mapActions } from "vuex";
export default {
    data () {
        return {
            editor: null,
            url: {
                getUserinfo: "lims/weChat/getUserinfo",
                loginByWorkNo: "/sys/loginByWorkNo",
            },
            code: "WpeXPCwPndJ9YrO2LWBgkYUfM0ftW-BD4sZ7YhFOGPc",
            token:
                'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjIzOTI2NzIsInVzZXJuYW1lIjoiYWRtaW4ifQ.D06SHDy4GuQWdI-39cmDrDdcSc6Ex0spSNG2gTAgtk0',
            userInfo: {
                id: "e9ca23d68d884d4ebb19d07889727dae",
                username: "admin",
                realname: "管理员",
                avatar:
                    "https://bcebos.cloud.geely.com/v1/lj-b-test-experdata-bos/Penguins.jpg?authorization=bce-auth-v1%2F71c1cbbcd10845d19b19ee7f2e8d7ed9%2F2023-08-23T08%3A27%3A03Z%2F-1%2F%2F087ff42cc476c4117f432e82b1a0680646c31b54f9a29e629a07571d418a71c2",
                birthday: "2018-12-05",
                sex: 1,
                email: "944937992@qq.com",
                phone: "186****1111",
                orgCode: "A02",
                orgCodeTxt: "lims系统",
                status: 1,
                delFlag: 0,
                workNo: "00001",
                post: "试验工程师",
                telephone: null,
                createBy: null,
                createTime: "2019-06-21 00:00:00",
                updateBy: "admin",
                updateTime: "2023-08-17 00:00:00",
                activitiSync: 1,
                userIdentity: 2,
                departIds: "",
                relTenantIds: "",
                clientId: null,
                homePath: null,
                externalAccount: "0",
                empowerDomain: "word",
                qualificationFile: null,
                qualificationRemark: null,
                domainAccount: null,
                firstNamePy: null,
                isQuit: null,
                param1: null,
            },
        };
    },
    created () {
        this.handleLogin();
    },
    methods: {
        // createEditor() {
        //   const editorConfig = {
        //     language: "zh-CN",
        //     // 编辑器宽度
        //     width: "100%",
        //     // 编辑器高度
        //     height: 800,
        //     // 编辑器类型，支持 word（文档）、cell（表格）、slide（PPT）
        //     documentType: "cell",
        //     // 文档配置
        //     document: {
        //       // 文件类型
        //       fileType: "xlsx",
        //       // 文档标识符
        //       key: "test1.xlsx",
        //       // 文档地址，绝对路径
        //       url: "https://bcebos.cloud.geely.com/v1/lj-b-test-experdata-bos/%E6%95%B4%E8%BD%A6%E8%AF%95%E9%AA%8C%E7%AD%96%E5%88%92-%E6%96%B01710843923611.xlsx?authorization=bce-auth-v1%2F71c1cbbcd10845d19b19ee7f2e8d7ed9%2F2024-03-19T10%3A25%3A24Z%2F-1%2F%2F4c0e897233fd1a9a061df27013b81b1bbfc7ce3682200f4f1e6effb331de57d8",
        //       // 文档标题
        //       title: "测试文档一.xlsx",
        //       permissions: {
        //         // 启用评论
        //         comment: false,
        //         // 启用下载
        //         download: true,
        //         // 启用编辑
        //         edit: false,
        //         // 启用导出
        //         print: true,
        //         // 启用预览
        //         review: true,
        //       },
        //     },
        //     editorConfig: {
        //       lang: "zh-CN",
        //     },
        //   };

        //   this.editor = new window.DocsAPI.DocEditor("onlyoffice", editorConfig);
        // },
        ...mapActions(["SetToken"]),
        handleLogin () {
            getAction(this.url.getUserinfo, { code: this.$route.query.code }).then(
                (res) => {
                    if (res.userid) {
                        getAction(this.url.loginByWorkNo, { workNo: res.userid }).then(
                            (res) => {
                                console.log(res);
                                if (res.success) {
                                    this.token = res.result.token;
                                    this.userInfo = res.result.userInfo;
                                    this.SetToken({
                                        token: this.token,
                                        userInfo: this.userInfo,
                                    });
                                    queryUserRoleInfo({ userid: this.userInfo.id }).then(
                                        (res) => {
                                            console.log(res);
                                            if (res.success) {
                                                let roleId = [];
                                                let roleName = [];
                                                res.result.forEach((item) => {
                                                    roleId.push(item.id);
                                                    roleName.push(item.roleName);
                                                });
                                                this.userInfo.selectedroles = roleId.join(",");
                                                this.userInfo.selectedrolesName = roleName.join(",");
                                                this.SetToken({
                                                    token: this.token,
                                                    userInfo: this.userInfo,
                                                });
                                            } else {
                                                Notify({ type: "warning", message: res.message });
                                            }
                                        }
                                    );
                                    // selectedroles

                                    this.$router.replace({ path: "/dashboard", replace: true });
                                } else {
                                    Notify({ type: "warning", message: res.message });
                                }
                            }
                        );
                    } else {
                        this.SetToken({
                            token: this.token,
                            userInfo: this.userInfo,
                        });
                        this.$router.replace({ path: "/dashboard", replace: true });
                    }
                    console.log(res);
                }
            ).catch(err => {
                this.SetToken({
                    token: this.token,
                    userInfo: this.userInfo,
                });
                this.$router.replace({ path: "/dashboard", replace: true });
            })

            // setTimeout(() => {
            //   this.$router.replace({ path: "/dashboard", replace: true });
            // }, 1000);
        },
    },
};
</script>

<style lang="scss" scoped>
.loading-main {
    height: 100%;

    ::v-deep {
        .van-loading {
            margin-top: 100px;
        }
    }
}
</style>
